<template>
  <div>
    promise
    <button @click="set1">set1</button>
    <button @click="setPromise">promise</button>
  </div>
</template>

<script>
export default {
  data () {
    return {
      name1: '',
      name2: '',
      isSet1Success: true,
      isSet2Success: true
    }
  },
  mounted () {
    this.go1()
  },
  methods: {
    go1 () {
      console.log('i am go1')
    },
    set1 () {
      setTimeout(() => {
        if (this.isSet1Success) {
          this.name1 = 'ygy'
          this.go2()
        } else {
          console.log('失败')
        }
      }, 1000)
    },
    set2 () {
    },
    go2 () {
      setTimeout(() => {
        if (this.isSet2Success) {
          this.name2 = 'lsf'
          console.log(this.name1, this.name2)
        } else {
          console.log('失败')
        }
      }, 1000)
    },
    setPromise () {
      const getAxios = this.newPromise()
      getAxios.then(r => {
        console.log(11, r)
      }).catch(r => {
        console.log(22, r)
      })
    },
    newPromise () {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          const list = ['list']
          if (list) {
            resolve(list)
          } else {
            reject('404')
          }
        }, 1000)
      })
    }
  }
}
</script>
